<template>
  <div class="app-container">
    <el-form ref="form" :model="form" :rules="rules" label-width="200px">
      <div class="itemList">
        <el-form-item label="视频/评价_音量调整" prop="videovolume">
          <el-input v-model="form.videovolume" style="width:100px"/>
          <span style="margin-left: 16px">(调节范围1-20)</span>
        </el-form-item>
      </div>
      <div class="itemList">
        <el-form-item label="员工_信息字体调整:字号" prop="workerinfofontsize">
          <el-input v-model="form.workerinfofontsize" style="width:100px"/>
        </el-form-item>
        <el-form-item label="颜色" prop="workerinfofontsizefontcolor" label-width="100px">
          <el-color-picker v-model="form.workerinfofontsizefontcolor"></el-color-picker>
        </el-form-item>
      </div>
      <div class="itemList">
        <el-form-item label="日期_信息字体调整:字号" prop="nowdatefontsize">
          <el-input v-model="form.nowdatefontsize" style="width:100px"/>
        </el-form-item>
        <el-form-item label="颜色" prop="nowdatefontcolor" label-width="100px">
          <el-color-picker v-model="form.nowdatefontcolor"></el-color-picker>
        </el-form-item>
      </div>
      <div class="itemList">
        <el-form-item label="滚动_信息字体调整:字号" prop="scrollingtextfontsize">
          <el-input v-model="form.scrollingtextfontsize" style="width:100px"/>
        </el-form-item>
        <el-form-item label="颜色" prop="scrollingtextfontcolor" label-width="100px">
          <el-color-picker v-model="form.scrollingtextfontcolor"></el-color-picker>
        </el-form-item>
        <el-form-item label="滚动方式" label-width="100px">
          <el-select placeholder="请选择" style="width:100px" v-model="form.scrollingtexttype">
            <el-option key="滚动" label="滚动" value="滚动"/>
            <el-option key="静止" label="静止" value="静止"/>
          </el-select>
        </el-form-item>
      </div>

    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
    </div>

  </div>
</template>

<style>
.app-container {
  display: flex;
  flex-direction: column;
}

.itemList {
  display: flex;
  flex-direction: row;
}
</style>

<script>
import {listPorfile, getPorfile, delPorfile, addPorfile, updatePorfile} from "@/api/manager/porfile";

export default {
  name: "Porfile",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 字体设置表格数据
      porfileList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {
        nowdatefontcolor: '',
        workerinfofontsizefontcolor: '',
        scrollingtextfontcolor: ''
      },
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.handleUpdate();
  },
  methods: {
    /** 查询字体设置列表 */
    getList() {
      this.loading = true;
      listPorfile(this.queryParams).then(response => {
        this.porfileList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.handleUpdate();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        organid: null,
        triggermode: null,
        adsmode: null,
        videovolume: null,
        weatherinfo: null,
        weathercity: null,
        weatherinfoFontsize: null,
        weatherinfofontcolor: null,
        weatherinfoFontName: null,
        nowdatefontsize: null,
        nowdatefontcolor: null,
        nowdatefontName: null,
        workerinfofontsize: null,
        workerinfofontsizefontcolor: null,
        workerInfofontName: null,
        scrollingtextfontsize: null,
        scrollingtextfontcolor: null,
        scrollingtextfontname: null,
        scrollingtexttype: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加字体设置";
    },
    /** 修改按钮操作 */
    handleUpdate() {
      this.reset();
      const id = 1
      getPorfile(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改字体设置";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePorfile(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPorfile(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除字体设置编号为"' + ids + '"的数据项？').then(function () {
        return delPorfile(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('manager/porfile/export', {
        ...this.queryParams
      }, `porfile_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
